﻿using System.Web;
using L.Basic.Cache;

namespace L.Cache.Web
{
    public class WebCache : ICache
    {

        #region ICache 成员

        public object GetApplicationCache(string key)
        {
            return HttpContext.Current.Application[key];
        }
        public T GetApplicationCache<T>(string key)
        {
            var value = GetApplicationCache(key);
            if (value is T)
                return (T)value;
            return default(T);
        }
        public void SetApplicationCache(string key, object obj)
        {
            HttpContext.Current.Application.Add(key, obj);
        }

        public void RemoveApplicationCache(string key)
        {
            HttpContext.Current.Application.Remove(key);
        }

        public object GetSessionCache(string key)
        {
            return HttpContext.Current.Session[key];
        }
        public T GetSessionCache<T>(string key)
        {
            var value = GetSessionCache(key);
            if (value is T)
                return (T)value;
            return default(T);
        }
        public void SetSessionCache(string key, object obj)
        {
            HttpContext.Current.Session.Add(key, obj);
        }

        public void RemoveSessionCache(string key)
        {
            HttpContext.Current.Session.Remove(key);
        }
        #endregion





    }
}
